#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	string T;
	cin >> T;

	int n = T.length();
	vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(n + 1, vector<int>(n + 1, 0)));

	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= i; ++j) {
			for (int k = 0; k <= i; ++k) {
				if (T[i - 1] == 'a' && j > 0) {
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k] + 1);
				}
				else if (T[i - 1] == 'b' && j > 0) {
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k] + 1);
				}
				else if (T[i - 1] == 'c' && k > 0) {
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k - 1] + 1);
				}
				else if (T[i - 1] == 'd' && k > 0) {
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k - 1] + 1);
				}
				else if (T[i - 1] == 'e') {
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k] + 1);
				}
				else if (T[i - 1] == 'f') {
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k] + 1);
				}
				dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k]);
			}
		}
	}

	int maxLength = 0;
	for (int j = 1; j <= n; ++j) {
		for (int k = 1; k <= n; ++k) {
			maxLength = max(maxLength, dp[n][j][k]);
		}
	}

	cout << maxLength << endl;

	return 0;
}